package alibaba.d20210910.t2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @author habitplus
 * @since 2021-09-10 19:44
 */
public class Main {
    private static final StreamTokenizer st = new StreamTokenizer(
            new BufferedReader(new InputStreamReader(System.in)));

    static int nextInt() {
        try {
            st.nextToken();
            return (int) st.nval;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }

    private static int solve(int a, int b, int c, int d, int x, int y) {
        int max = Math.max(x, y);

        int k = 0;
        int sz = 2;
        int[][] dd = {{a, b}, {d, c}};
        while (sz < max){
            sz <<= 1;
            k++;
        }

        // max <= sz

        int i = x > sz / 2 ? 1 : 0;
        int j = y > sz / 2 ? 1 : 0;

        int ss = dd[i][j];



        return 1;
    }

    public static void main(String[] args) {
        int a = nextInt();
        int c = nextInt();
        int b = nextInt();
        int d = nextInt();
        int t = nextInt();
        int x, y, ans;
        while (t-- > 0) {
            x = nextInt();
            y = nextInt();
            ans = solve(a, b, c, d, x, y);
            System.out.println(ans);
        }
    }
}
